package com.ssy.bus.controller;

import com.ssy.bus.pojo.Supplier;
import com.ssy.bus.service.ISupplierService;
import com.ssy.bus.vo.SupplierVo;
import com.ssy.common.utils.PageResult;
import com.ssy.common.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author ssy
 * 供应商维护
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private ISupplierService supplierService;

    /**
     * 供应商的分页查询
     *
     * @param supplierVo
     * @return
     */
    @GetMapping("/loadAllSupplierPage")
    public PageResult loadAllSupplierPage(SupplierVo supplierVo) {
        return this.supplierService.loadAllSupplierPage(supplierVo);
    }

    /**
     * 添加供应商
     *
     * @param supplier
     * @return
     */
    @PostMapping("/addSupplier")
    public Result addSupplier(@RequestBody Supplier supplier) {
        supplier.setCreateTime(new Date());
        return this.supplierService.insertSupplier(supplier);
    }

    /**
     * 修改供应商
     *
     * @param supplier
     * @return
     */
    @PostMapping("/updateSupplier")
    public Result updateSupplier(@RequestBody Supplier supplier) {
        return this.supplierService.updateSupplier(supplier);
    }

    /**
     * 删除供应商
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteSupplier/{id}")
    public Result deleteSupplier(@PathVariable Integer id) {
        return this.supplierService.deleteSupplierById(id);
    }

    /**
     * 批量删除供应商
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/bathDeleteSupplier/{ids}")
    public Result bathDeleteSupplier(@PathVariable Integer[] ids) {
        return this.supplierService.bathDeleteSupplier(ids);
    }

    /**
     * 修改供应商状态
     *
     * @param id
     * @param state
     * @return
     */
    @PostMapping("/updateSupplierState/{id}/{state}")
    public Result updateSupplierState(@PathVariable Integer id, @PathVariable Integer state) {
        Supplier supplier = new Supplier();
        supplier.setId(id);
        supplier.setState(state);
        return this.supplierService.updateSupplier(supplier);
    }

}
